#define _CRT_SECURE_NO_WARNINGS 1
#include<bits/stdc++.h>

using namespace std;

struct node
{
	int num;
	int dis;
};

bool cmp(node a, node b)
{
	if (a.dis != b.dis)
	{
		return a.dis < b.dis;
	}
	else
	{
		return a.num < b.num;
	}
}
int get_dis(int num, int max, int min)
{
	return abs(abs(num - max) - (num - min));
}

int main()
{
	int n, max, min;

	cin >> n;
	vector<int> num;
	cin >> max;
	min = max;

	for (int i = 1; i < n; i++)
	{
		int temp;
		cin >> temp;
		if (temp > max)
		{
			max = temp;
		}
		else if (temp < min)
		{
			min = temp;
		}
		num.push_back(temp);
	}

	vector<node> res;

	for (int i = 0; i < n; i++)
	{
		node temp;
		temp.num = num[i];
		temp.dis = get_dis(num[i], max, min);
		res.push_back(temp);
	}
	sort(res.begin(), res.end(), cmp);
	cout << res[0].num << endl;
	return 0;
}



